<?php
/**
 * product_listing module
 *
 * @package modules
 * @copyright Copyright 2003-2011 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: product_listing.php 18695 2011-05-04 05:24:19Z drbyte $
 */
if (!defined('IS_ADMIN_FLAG')) {
  die('Illegal Access');
}
$show_submit = zen_run_normal();
//echo $listing_sql;
$listing_split = new splitPageResults($listing_sql, MAX_DISPLAY_PRODUCTS_LISTING, 'p.products_id', 'page');
$zco_notifier->notify('NOTIFY_MODULE_PRODUCT_LISTING_RESULTCOUNT', $listing_split->number_of_rows);
$how_many = 0;

$zc_col_count_description = 0;
$lc_align = '';
if ($listing_split->number_of_rows > 0) {
  $parameters = zen_get_all_get_params(array('main_page', 'info', 'x', 'y'));
  $rows = 0;
  $listing = $db->Execute($listing_split->sql_query);
  $extra_row = 0;
  while (!$listing->EOF) {
    if ((($rows-$extra_row)/2) == floor(($rows-$extra_row)/2)) {
      $list_box_contents[$rows] = array('params' => 'class="productListing-even"');
    } else {
      $list_box_contents[$rows] = array('params' => 'class="productListing-odd"');
    }

    if (is_feature_product($listing->fields['products_id'])){
    	$list_box_contents[$rows]['is_featured'] = true;
    }
    $cur_row = sizeof($list_box_contents) - 1;
    $sale_discount = zen_get_products_save($listing->fields['products_id'],1);
    if ($sale_discount!=''){
    	$special_flag = '<span class="index_icon-discount-s">'.$sale_discount.'</span>';
    }else{
    	$special_flag = '';
    } 
    $products_desc = array();
    explode_utf8_str(preg_replace('[\r\n]','',strip_tags($listing->fields['products_description'])),120,$products_desc);
    $list_box_contents[$rows][0]['params'] = 'class="products_list_image"';
    if ($view_style=='gallery')
		$list_box_contents[$rows][0]['text'] = '<a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), $parameters.'products_id='.$listing->fields['products_id']) . '">' .$special_flag.zen_image(DIR_WS_IMAGES . $listing->fields['products_image'], $listing->fields['products_name'], 210, 210, 'class="listingProductImage"') . '</a>';
	else
    	$list_box_contents[$rows][0]['text'] = '<a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), $parameters.'products_id='.$listing->fields['products_id']) . '">' .$special_flag.zen_image(DIR_WS_IMAGES . $listing->fields['products_image'], $listing->fields['products_name'], IMAGE_PRODUCT_LISTING_WIDTH, IMAGE_PRODUCT_LISTING_HEIGHT, 'class="listingProductImage"') . '</a>'; 
    $list_box_contents[$rows][1]['params'] = 'class="products_list_des"';
	$list_box_contents[$rows][1]['text'] = '<h3 class="itemTitle"><a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), $parameters.'products_id='.$listing->fields['products_id']) . '">' . $listing->fields['products_name'] . '</a></h3><div class="listingDescription">' . zen_trunc_string(zen_clean_html(stripslashes(zen_get_products_description($listing->fields['products_id'], $_SESSION['languages_id']))), PRODUCT_LIST_DESCRIPTION).'</h3>';
	if ($view_style=='list')
		$list_box_contents[$rows][1]['text'] .= '<div><b>Description:</b>'.$products_desc[0].'...<br /><a href="'.zen_href_link(zen_get_info_page($listing->fields['products_id']), $parameters.'&products_id='.$listing->fields['products_id']) .'">Product Detail >></a></div>';
	if (is_new_product($listing->fields['products_id']))
		$list_box_contents[$rows][1]['text'] .= '<div class="is_new_product"><img src="'.DIR_WS_TEMPLATE_IMAGES.'newflag1.gif" alt="new"></div>';
	
	$list_box_contents[$rows][2]['params'] = 'class="products_list_price"';    
    $products_price = $currencies->display_price((zen_get_products_actual_price($listing->fields['products_id'])),0);
	$list_box_contents[$rows][2]['text'] = '<div class="actual_price">'.$products_price.'</div>';
  	$reviews_info=array();
	if (has_review($listing->fields['products_id'],$reviews_info)){
		$list_box_contents[$rows][2]['text'] .= '<div style="margin-top:5px;">Reviews:<img src="'.DIR_WS_TEMPLATES.'template_default/images/stars_'.$reviews_info['average_rating'].'_small.gif'.'" alt="reviews rating">'.$reviews_info['reviews_total'].'Reviews</div>';
	}
    $listing->MoveNext();
    $rows++;
  }
  $error_categories = false;
} else {
  $list_box_contents = array();

  $list_box_contents[0] = array('params' => 'class="productListing-odd"');
  $list_box_contents[0][] = array('params' => 'class="productListing-data"',
                                              'text' => 'NO Products');

  $error_categories = true;
}
if (($how_many > 0 and $show_submit == true and $listing_split->number_of_rows > 0) and (PRODUCT_LISTING_MULTIPLE_ADD_TO_CART == 1 or  PRODUCT_LISTING_MULTIPLE_ADD_TO_CART == 3) ) {
  $show_top_submit_button = true;
} else {
  $show_top_submit_button = false;
}
if (($how_many > 0 and $show_submit == true and $listing_split->number_of_rows > 0) and (PRODUCT_LISTING_MULTIPLE_ADD_TO_CART >= 2) ) {
  $show_bottom_submit_button = true;
} else {
  $show_bottom_submit_button = false;
}



  if ($how_many > 0 && PRODUCT_LISTING_MULTIPLE_ADD_TO_CART != 0 and $show_submit == true and $listing_split->number_of_rows > 0) {
  // bof: multiple products
    echo zen_draw_form('multiple_products_cart_quantity', zen_href_link(FILENAME_DEFAULT, zen_get_all_get_params(array('action')) . 'action=multiple_products_add_product', $request_type), 'post', 'enctype="multipart/form-data"');
  }

